package com.aso114.project.adapter;

import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.aso114.project.R;
import com.aso114.project.base.BaseApplication;
import com.bumptech.glide.Glide;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by asus on 2019/1/29.
 */

public class PicAdapter extends BaseAdapter {
    private ArrayList list = new ArrayList();
    private Context context;

    public PicAdapter(Context context, ArrayList formatImages) {
        this.context = context;
        this.list = formatImages;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView != null) {
            holder = (ViewHolder) convertView.getTag();
        } else {
            convertView = LayoutInflater.from(BaseApplication.getInstance().getBaseContext()).inflate(R.layout.item_pic, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        Glide.with(BaseApplication.getInstance().getApplicationContext()).load(list.get(position).toString()).into(holder.itemPic);
        return convertView;
    }

    public void setData(ArrayList formatImages) {
        this.list = formatImages;
    }

    static class ViewHolder {
        @BindView(R.id.item_pic)
        ImageView itemPic;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
